<!DOCTYPE html><html lang="zh-CN" data-theme="light"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width,initial-scale=1"><title>MySQL之Explain性能分析 | Kylin</title><meta name="keywords" content="数据库,MySQL"><meta name="author" content="Kylin"><meta name="copyright" content="Kylin"><meta name="format-detection" content="telephone=no"><meta name="theme-color" content="#ffffff"><meta name="description" content="简介查看执行计划，使用Explain关键字可以模拟优化器执行SQL查询语句，从而知道MySQL是如何处理你的SQL 语句的。分析你的查询语句或是表结构的性能瓶颈。 能干嘛？  表的读取顺序 哪些索引可以使用 数据读取操作的操作类型 哪些索引被实际引用 表之间的引用 每张表有多少行被物理查询  使用：Explain + SQL语句   id(重要)select查询的序列号,包含一组数字，表示查询中执">
<meta property="og:type" content="article">
<meta property="og:title" content="MySQL之Explain性能分析">
<meta property="og:url" content="https://www.codekylin.cn/15002.html">
<meta property="og:site_name" content="Kylin">
<meta property="og:description" content="简介查看执行计划，使用Explain关键字可以模拟优化器执行SQL查询语句，从而知道MySQL是如何处理你的SQL 语句的。分析你的查询语句或是表结构的性能瓶颈。 能干嘛？  表的读取顺序 哪些索引可以使用 数据读取操作的操作类型 哪些索引被实际引用 表之间的引用 每张表有多少行被物理查询  使用：Explain + SQL语句   id(重要)select查询的序列号,包含一组数字，表示查询中执">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://qiniu.codekylin.cn/github/img/img/deepin-1.png">
<meta property="article:published_time" content="2020-10-25T11:22:26.000Z">
<meta property="article:modified_time" content="2022-07-12T11:46:57.232Z">
<meta property="article:author" content="Kylin">
<meta property="article:tag" content="数据库">
<meta property="article:tag" content="MySQL">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://qiniu.codekylin.cn/github/img/img/deepin-1.png"><link rel="shortcut icon" href="https://qiniu.codekylin.cn/img/20200807181548.png"><link rel="canonical" href="https://www.codekylin.cn/15002"><link rel="preconnect" href="//cdn.jsdelivr.net"/><link rel="preconnect" href="//www.google-analytics.com" crossorigin=""/><link rel="preconnect" href="//hm.baidu.com"/><link rel="preconnect" href="//fonts.googleapis.com" crossorigin=""/><meta name="google-site-verification" content="gzeyWstt6NoTZKh7YFYNLNziL8HIZ8YH2Ug7xTDX5-Y"/><link rel="stylesheet" href="/css/index.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free/css/all.min.css" media="print" onload="this.media='all'"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/node-snackbar/dist/snackbar.min.css" media="print" onload="this.media='all'"><script>var _hmt = _hmt || [];
(function() {
  var hm = document.createElement("script");
  hm.src = "https://hm.baidu.com/hm.js?f76c34daefe747deee7c7be3ead2ba80";
  var s = document.getElementsByTagName("script")[0]; 
  s.parentNode.insertBefore(hm, s);
})();
</script><script async="async" src="https://www.googletagmanager.com/gtag/js?id=UA-159334016-1"></script><script>window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'UA-159334016-1');
</script><link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Titillium+Web" media="print" onload="this.media='all'"><script>const GLOBAL_CONFIG = { 
  root: '/',
  algolia: undefined,
  localSearch: {"path":"search.xml","languages":{"hits_empty":"找不到您查询的内容：${query}"}},
  translate: {"defaultEncoding":2,"translateDelay":0,"msgToTraditionalChinese":"繁","msgToSimplifiedChinese":"简"},
  noticeOutdate: {"limitDay":90,"position":"top","messagePrev":"自上次更新以来已经","messageNext":"天，文章的内容可能已过时或存在差异。"},
  highlight: {"plugin":"highlighjs","highlightCopy":true,"highlightLang":true,"highlightHeightLimit":false},
  copy: {
    success: '复制成功',
    error: '复制错误',
    noSupport: '浏览器不支持'
  },
  relativeDate: {
    homepage: false,
    post: false
  },
  runtime: '天',
  date_suffix: {
    just: '刚刚',
    min: '分钟前',
    hour: '小时前',
    day: '天前',
    month: '个月前'
  },
  copyright: {"limitCount":50000,"languages":{"author":"作者: Kylin","link":"链接: ","source":"来源: Kylin","info":"著作权归作者所有。商业转载请联系作者获得授权，非商业转载请注明出处。"}},
  lightbox: 'fancybox',
  Snackbar: {"chs_to_cht":"你已切换为繁体","cht_to_chs":"你已切换为简体","day_to_night":"你已切换为深色模式","night_to_day":"你已切换为浅色模式","bgLight":"#FF0000","bgDark":"#2d3035","position":"bottom-left"},
  source: {
    jQuery: 'https://cdn.jsdelivr.net/npm/jquery@latest/dist/jquery.min.js',
    justifiedGallery: {
      js: 'https://cdn.jsdelivr.net/npm/justifiedGallery/dist/js/jquery.justifiedGallery.min.js',
      css: 'https://cdn.jsdelivr.net/npm/justifiedGallery/dist/css/justifiedGallery.min.css'
    },
    fancybox: {
      js: 'https://cdn.jsdelivr.net/npm/@fancyapps/fancybox@latest/dist/jquery.fancybox.min.js',
      css: 'https://cdn.jsdelivr.net/npm/@fancyapps/fancybox@latest/dist/jquery.fancybox.min.css'
    }
  },
  isPhotoFigcaption: false,
  islazyload: true,
  isanchor: false
}</script><script id="config-diff">var GLOBAL_CONFIG_SITE = { 
  isPost: true,
  isHome: false,
  isHighlightShrink: false,
  isToc: true,
  postUpdate: '2022-07-12 19:46:57'
}</script><noscript><style type="text/css">
  #nav {
    opacity: 1
  }
  .justified-gallery img {
    opacity: 1
  }

  #recent-posts time,
  #post-meta time {
    display: inline !important
  }
</style></noscript><script>(win=>{
    win.saveToLocal = {
      set: function setWithExpiry(key, value, ttl) {
        if (ttl === 0) return
        const now = new Date()
        const expiryDay = ttl * 86400000
        const item = {
          value: value,
          expiry: now.getTime() + expiryDay,
        }
        localStorage.setItem(key, JSON.stringify(item))
      },

      get: function getWithExpiry(key) {
        const itemStr = localStorage.getItem(key)

        if (!itemStr) {
          return undefined
        }
        const item = JSON.parse(itemStr)
        const now = new Date()

        if (now.getTime() > item.expiry) {
          localStorage.removeItem(key)
          return undefined
        }
        return item.value
      }
    }
  
    win.getScript = url => new Promise((resolve, reject) => {
      const script = document.createElement('script')
      script.src = url
      script.async = true
      script.onerror = reject
      script.onload = script.onreadystatechange = function() {
        const loadState = this.readyState
        if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
        script.onload = script.onreadystatechange = null
        resolve()
      }
      document.head.appendChild(script)
    })
  
      win.activateDarkMode = function () {
        document.documentElement.setAttribute('data-theme', 'dark')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#0d0d0d')
        }
      }
      win.activateLightMode = function () {
        document.documentElement.setAttribute('data-theme', 'light')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#ffffff')
        }
      }
      const t = saveToLocal.get('theme')
    
          const isDarkMode = window.matchMedia('(prefers-color-scheme: dark)').matches
          const isLightMode = window.matchMedia('(prefers-color-scheme: light)').matches
          const isNotSpecified = window.matchMedia('(prefers-color-scheme: no-preference)').matches
          const hasNoSupport = !isDarkMode && !isLightMode && !isNotSpecified

          if (t === undefined) {
            if (isLightMode) activateLightMode()
            else if (isDarkMode) activateDarkMode()
            else if (isNotSpecified || hasNoSupport) {
              const now = new Date()
              const hour = now.getHours()
              const isNight = hour <= 6 || hour >= 18
              isNight ? activateDarkMode() : activateLightMode()
            }
            window.matchMedia('(prefers-color-scheme: dark)').addListener(function (e) {
              if (saveToLocal.get('theme') === undefined) {
                e.matches ? activateDarkMode() : activateLightMode()
              }
            })
          } else if (t === 'light') activateLightMode()
          else activateDarkMode()
        
      const asideStatus = saveToLocal.get('aside-status')
      if (asideStatus !== undefined) {
        if (asideStatus === 'hide') {
          document.documentElement.classList.add('hide-aside')
        } else {
          document.documentElement.classList.remove('hide-aside')
        }
      }
    
    const fontSizeVal = saveToLocal.get('global-font-size')
    if (fontSizeVal !== undefined) {
      document.documentElement.style.setProperty('--global-font-size', fontSizeVal + 'px')
    }
    })(window)</script><link rel="stylesheet" href="https://qiniu.codekylin.cn/github/img/img/custom.css"><link rel="stylesheet" href="//at.alicdn.com/t/font_1993646_z05rabxf05h.css"><link rel="stylesheet" href="https://qiniu.codekylin.cn/github/img/img/icon.css"><meta name="generator" content="Hexo 5.4.0"><link rel="alternate" href="/atom.xml" title="Kylin" type="application/atom+xml">
</head><body><div id="web_bg"></div><div id="sidebar"><div id="menu-mask"></div><div id="sidebar-menus"><div class="author-avatar"><img class="avatar-img" data-lazy-src="https://qiniu.codekylin.cn/img/20200807181526.jpg" onerror="onerror=null;src='https://qiniu.codekylin.cn/github/img/friend_404.gif'" alt="avatar"/></div><div class="site-data"><div class="data-item is-center"><div class="data-item-link"><a href="/archives/"><div class="headline">文章</div><div class="length-num">362</div></a></div></div><div class="data-item is-center"><div class="data-item-link"><a href="/tags/"><div class="headline">标签</div><div class="length-num">427</div></a></div></div><div class="data-item is-center"><div class="data-item-link"><a href="/categories/"><div class="headline">分类</div><div class="length-num">101</div></a></div></div></div><hr/><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw fa fa-home"></i><span> 首页</span></a></div><div class="menus_item"><a class="site-page" href="/archives/"><i class="fa-fw fa fa-archive"></i><span> 时间轴</span></a></div><div class="menus_item"><a class="site-page" href="/tags/"><i class="fa-fw fa fa-tags"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="/categories/"><i class="fa-fw fa fa-folder-open"></i><span> 分类</span></a></div><div class="menus_item"><a class="site-page" href="/link/"><i class="fa-fw fa fa-link"></i><span> 友链</span></a></div><div class="menus_item"><a class="site-page" href="/about/"><i class="fa-fw fa fa-heart"></i><span> 关于</span></a></div></div></div></div><div class="post" id="body-wrap"><header class="post-bg" id="page-header" style="background-image: url('https://qiniu.codekylin.cn/github/img/img/deepin-1.png')"><nav id="nav"><span id="blog_name"><a id="site-name" href="/">Kylin</a></span><div id="menus"><div id="search-button"><a class="site-page social-icon search"><i class="fas fa-search fa-fw"></i><span> 搜索</span></a></div><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw fa fa-home"></i><span> 首页</span></a></div><div class="menus_item"><a class="site-page" href="/archives/"><i class="fa-fw fa fa-archive"></i><span> 时间轴</span></a></div><div class="menus_item"><a class="site-page" href="/tags/"><i class="fa-fw fa fa-tags"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="/categories/"><i class="fa-fw fa fa-folder-open"></i><span> 分类</span></a></div><div class="menus_item"><a class="site-page" href="/link/"><i class="fa-fw fa fa-link"></i><span> 友链</span></a></div><div class="menus_item"><a class="site-page" href="/about/"><i class="fa-fw fa fa-heart"></i><span> 关于</span></a></div></div><div id="toggle-menu"><a class="site-page"><i class="fas fa-bars fa-fw"></i></a></div></div></nav><div id="post-info"><h1 class="post-title">MySQL之Explain性能分析</h1><div id="post-meta"><div class="meta-firstline"><span class="post-meta-date"><i class="far fa-calendar-alt fa-fw post-meta-icon"></i><span class="post-meta-label">发表于</span><time class="post-meta-date-created" datetime="2020-10-25T11:22:26.000Z" title="发表于 2020-10-25 19:22:26">2020-10-25</time><span class="post-meta-separator">|</span><i class="fas fa-history fa-fw post-meta-icon"></i><span class="post-meta-label">更新于</span><time class="post-meta-date-updated" datetime="2022-07-12T11:46:57.232Z" title="更新于 2022-07-12 19:46:57">2022-07-12</time></span><span class="post-meta-categories"><span class="post-meta-separator">|</span><i class="fas fa-inbox fa-fw post-meta-icon"></i><a class="post-meta-categories" href="/categories/%E6%95%B0%E6%8D%AE%E5%BA%93/">数据库</a><i class="fas fa-angle-right post-meta-separator"></i><i class="fas fa-inbox fa-fw post-meta-icon"></i><a class="post-meta-categories" href="/categories/%E6%95%B0%E6%8D%AE%E5%BA%93/MySQL/">MySQL</a></span></div><div class="meta-secondline"><span class="post-meta-separator">|</span><span class="post-meta-wordcount"><i class="far fa-file-word fa-fw post-meta-icon"></i><span class="post-meta-label">字数总计:</span><span class="word-count">2k</span><span class="post-meta-separator">|</span><i class="far fa-clock fa-fw post-meta-icon"></i><span class="post-meta-label">阅读时长:</span><span>6分钟</span></span></div></div></div></header><main class="layout" id="content-inner"><div id="post"><article class="post-content" id="article-container"><h2 id="简介"><a href="#简介" class="headerlink" title="简介"></a>简介</h2><p><strong>查看执行计划，使用<code>Explain</code>关键字可以模拟优化器执行SQL查询语句，从而知道MySQL是如何处理你的SQL 语句的。分析你的查询语句或是表结构的性能瓶颈。</strong></p>
<p>能干嘛？</p>
<ol>
<li>表的读取顺序</li>
<li>哪些索引可以使用</li>
<li>数据读取操作的操作类型</li>
<li><strong>哪些索引被实际引用</strong></li>
<li>表之间的引用</li>
<li><strong>每张表有多少行被物理查询</strong></li>
</ol>
<p>使用：<code>Explain + SQL语句</code></p>
<p><img src= "https://gitee.com/kylincw/images/raw/master/loading.gif" data-lazy-src="https://qiniu.codekylin.cn/github/img/img20201025193017.png" alt="image-20201025193015437"></p>
<p><img src= "https://gitee.com/kylincw/images/raw/master/loading.gif" data-lazy-src="https://qiniu.codekylin.cn/github/img/img20201025193036.png" alt="image-20201025193034670"></p>
<h2 id="id-重要"><a href="#id-重要" class="headerlink" title="id(重要)"></a>id(重要)</h2><p><strong>select查询的序列号,包含一组数字，表示查询中执行select子句或操作表的顺序</strong></p>
<p><strong><mark>id相同，执行顺序由上至下</mark></strong></p>
<p><img src= "https://gitee.com/kylincw/images/raw/master/loading.gif" data-lazy-src="https://qiniu.codekylin.cn/img/20201025200459.png" alt="image-20201025200351274"></p>
<p><strong><mark>id不同，如果是子查询，id的序号会递增，id值越大优先级越高，越先被执行。</mark></strong></p>
<p><img src= "https://gitee.com/kylincw/images/raw/master/loading.gif" data-lazy-src="https://qiniu.codekylin.cn/img/20201025200538.png" alt="image-20201025200536917"></p>
<p><mark><strong>id相同不同，同时存在。在所有组中，id值越大，优先级越高，越先执行 。id如果相同，可以认为是一组，从上往下顺序执行。</strong></mark></p>
<p>衍生 = <code>DERIVED</code></p>
<p><img src= "https://gitee.com/kylincw/images/raw/master/loading.gif" data-lazy-src="https://qiniu.codekylin.cn/img/20201025200931.png" alt="image-20201025200907983"></p>
<p><strong>如上图所示，在id为1时，table显示的是 <code>&lt;derived2&gt;</code> ,这里指的是指向id为2的表，即t3表的衍生表。</strong></p>
<p><strong><mark>id号每个号码，表示一趟独立的查询。一个sql 的查询趟数越少越好。</mark></strong></p>
<h2 id="select-type"><a href="#select-type" class="headerlink" title="select_type"></a>select_type</h2><p><img src= "https://gitee.com/kylincw/images/raw/master/loading.gif" data-lazy-src="https://qiniu.codekylin.cn/img/20201025201245.png" alt="image-20201025201243632"></p>
<p><strong>查询的类型，主要是用于区别普通查询、联合查询、子查询等的复杂查询。</strong></p>
<h3 id="SIMPLE"><a href="#SIMPLE" class="headerlink" title="SIMPLE"></a>SIMPLE</h3><p><strong>简单的 select 查询,查询中不包含子查询或者UNION</strong></p>
<p><img src= "https://gitee.com/kylincw/images/raw/master/loading.gif" data-lazy-src="https://qiniu.codekylin.cn/img/20201025201417.png" alt="image-20201025201415662"></p>
<h3 id="PRIMARY"><a href="#PRIMARY" class="headerlink" title="PRIMARY"></a>PRIMARY</h3><p><strong>查询中若包含任何复杂的子部分，最外层查询则被标记为Primary</strong></p>
<p><img src= "https://gitee.com/kylincw/images/raw/master/loading.gif" data-lazy-src="https://qiniu.codekylin.cn/img/20201025201638.png" alt="image-20201025201636255"></p>
<h3 id="DERIVED"><a href="#DERIVED" class="headerlink" title="DERIVED"></a>DERIVED</h3><p><strong>在<code>FROM</code>列表中包含的子查询被标记为DERIVED(衍生)。MySQL会递归执行这些子查询, 把结果放在临时表里。</strong></p>
<p><img src= "https://gitee.com/kylincw/images/raw/master/loading.gif" data-lazy-src="https://qiniu.codekylin.cn/img/20201025201638.png" alt="image-20201025201636255"></p>
<h3 id="SUBQUERY"><a href="#SUBQUERY" class="headerlink" title="SUBQUERY"></a>SUBQUERY</h3><p><strong>在<code>SELECT</code>或<code>WHERE</code>列表中包含了子查询</strong></p>
<p><img src= "https://gitee.com/kylincw/images/raw/master/loading.gif" data-lazy-src="https://qiniu.codekylin.cn/img/20201025201905.png" alt="image-20201025201903846"></p>
<h3 id="DEPENDENT-SUBQUERY"><a href="#DEPENDENT-SUBQUERY" class="headerlink" title="DEPENDENT SUBQUERY"></a>DEPENDENT SUBQUERY</h3><p><strong>在SELECT或WHERE列表中包含了子查询,子查询基于外层<code>IN</code></strong></p>
<p><img src= "https://gitee.com/kylincw/images/raw/master/loading.gif" data-lazy-src="https://qiniu.codekylin.cn/img/20201025202551.png" alt="image-20201025202300842"></p>
<h3 id="UNCACHEABLE-SUBQUREY"><a href="#UNCACHEABLE-SUBQUREY" class="headerlink" title="UNCACHEABLE SUBQUREY"></a>UNCACHEABLE SUBQUREY</h3><p> <strong>不可用缓存子查询，系统变量。</strong></p>
<p><img src= "https://gitee.com/kylincw/images/raw/master/loading.gif" data-lazy-src="https://qiniu.codekylin.cn/img/20201025202528.png" alt="image-20201025202526496"></p>
<h3 id="UNION"><a href="#UNION" class="headerlink" title="UNION"></a>UNION</h3><p>若第二个SELECT出现在UNION之后，则被标记为UNION；</p>
<p>若UNION包含在FROM子句的子查询中,外层SELECT将被标记为：DERIVED</p>
<p><img src= "https://gitee.com/kylincw/images/raw/master/loading.gif" data-lazy-src="https://qiniu.codekylin.cn/img/20201025202744.png" alt="image-20201025202742601"></p>
<h3 id="UNION-RESULT"><a href="#UNION-RESULT" class="headerlink" title="UNION RESULT"></a>UNION RESULT</h3><p>从UNION表获取结果的SELECT</p>
<p><img src= "https://gitee.com/kylincw/images/raw/master/loading.gif" data-lazy-src="https://qiniu.codekylin.cn/img/20201025202744.png" alt="image-20201025202742601"></p>
<h2 id="table"><a href="#table" class="headerlink" title="table"></a>table</h2><p>显示这一行的数据是关于哪张表的</p>
<h2 id="partitions"><a href="#partitions" class="headerlink" title="partitions"></a>partitions</h2><p>代表分区表中的命中情况，非分区表，该项为null</p>
<h2 id="type-优化"><a href="#type-优化" class="headerlink" title="type(优化)"></a>type(优化)</h2><p>type所显示的是查询使用了哪种类型，type包含的类型包括如下图所示的几种：</p>
<p><img src= "https://gitee.com/kylincw/images/raw/master/loading.gif" data-lazy-src="https://qiniu.codekylin.cn/img/20201025203432.png" alt="image-20201025203430417"></p>
<p>type显示的是访问类型，是较为重要的一个指标，结果 值从最好到最坏依次是 ： </p>
<p><code>system &gt; const &gt; eq_ref &gt; ref &gt; range &gt; index &gt; all</code></p>
<p><strong>一般来说，得保证查询至少达到range级别，最好能达到ref。</strong> </p>
<h3 id="system"><a href="#system" class="headerlink" title="system"></a>system</h3><p>表只有一行记录（等于系统表），这是<code>const</code>类型的特列，平时不会出现，这个也可以忽略不计</p>
<h3 id="const"><a href="#const" class="headerlink" title="const"></a>const</h3><p><strong>表示通过索引一次就找到了,const用于比较primary key或者unique索引。因为只匹配一行数据，所以很快。</strong></p>
<p>如将主键置于where列表中，MySQL就能将该查询转换为一个常量</p>
<p><img src= "https://gitee.com/kylincw/images/raw/master/loading.gif" data-lazy-src="https://qiniu.codekylin.cn/img/20201026150000.png" alt="image-20201026145957498"></p>
<h3 id="eq-ref"><a href="#eq-ref" class="headerlink" title="eq_ref"></a>eq_ref</h3><p><strong>唯一性索引扫描，对于每个索引键，表中只有一条记录与之匹配。常见于主键或唯一索引扫描。</strong></p>
<p><img src= "https://gitee.com/kylincw/images/raw/master/loading.gif" data-lazy-src="https://qiniu.codekylin.cn/img/20201026150313.png" alt="image-20201026150312675"></p>
<h3 id="ref"><a href="#ref" class="headerlink" title="ref"></a>ref</h3><p><strong>非唯一性索引扫描，返回匹配某个单独值的所有行。</strong></p>
<p>本质上也是一种索引访问，它返回所有匹配某个单独值的行，然而，它可能会找到多个符合条件的行，所以他应该属于查找和扫描的混合体</p>
<p><img src= "https://gitee.com/kylincw/images/raw/master/loading.gif" data-lazy-src="https://qiniu.codekylin.cn/img/20201026150620.png" alt="image-20201026150617981"></p>
<h3 id="range"><a href="#range" class="headerlink" title="range"></a>range</h3><p>只检索给定范围的行,使用一个索引来选择行。key 列显示使用了哪个索引</p>
<p><strong>一般就是在你的where语句中出现了between、&lt;、&gt;、in等的查询</strong></p>
<p>这种范围扫描索引扫描比全表扫描要好，因为它只需要开始于索引的某一点，而结束语另一点，不用扫描全部索引。</p>
<p><img src= "https://gitee.com/kylincw/images/raw/master/loading.gif" data-lazy-src="https://qiniu.codekylin.cn/img/20201026150729.png" alt="image-20201026150727791"></p>
<p><img src= "https://gitee.com/kylincw/images/raw/master/loading.gif" data-lazy-src="https://qiniu.codekylin.cn/img/20201026150747.png" alt="image-20201026150745528"></p>
<h3 id="index"><a href="#index" class="headerlink" title="index"></a>index</h3><p><strong>出现index是sql使用了索引但是没用通过索引进行过滤，一般是使用了覆盖索引或者是利用索引进行了排序分组。</strong></p>
<p><img src= "https://gitee.com/kylincw/images/raw/master/loading.gif" data-lazy-src="https://qiniu.codekylin.cn/img/20201026150934.png" alt="image-20201026150933574"></p>
<h3 id="all"><a href="#all" class="headerlink" title="all"></a>all</h3><p><strong>Full Table Scan，将遍历全表以找到匹配的行。</strong></p>
<p><img src= "https://gitee.com/kylincw/images/raw/master/loading.gif" data-lazy-src="https://qiniu.codekylin.cn/img/20201026151027.png" alt="image-20201026151025661"></p>
<h3 id="index-merge"><a href="#index-merge" class="headerlink" title="index_merge"></a>index_merge</h3><p><strong>在查询过程中需要多个索引组合使用，通常出现在有 <code>or</code>的关键字的sql中。</strong></p>
<p><img src= "https://gitee.com/kylincw/images/raw/master/loading.gif" data-lazy-src="https://qiniu.codekylin.cn/img/20201026151111.png" alt="image-20201026151110001"></p>
<h3 id="ref-or-null"><a href="#ref-or-null" class="headerlink" title="ref_or_null"></a>ref_or_null</h3><p>对于某个字段既需要关联条件，也需要<code>null</code>值得情况下。查询优化器会选择用ref_or_null连接查询。</p>
<p><img src= "https://gitee.com/kylincw/images/raw/master/loading.gif" data-lazy-src="https://qiniu.codekylin.cn/img/20201026151211.png" alt="image-20201026151209907"></p>
<h3 id="index-subquery"><a href="#index-subquery" class="headerlink" title="index_subquery"></a>index_subquery</h3><p>利用索引来关联子查询，不再全表扫描。</p>
<p><img src= "https://gitee.com/kylincw/images/raw/master/loading.gif" data-lazy-src="https://qiniu.codekylin.cn/img/20201026151401.png" alt="image-20201026151358456"></p>
<p><img src= "https://gitee.com/kylincw/images/raw/master/loading.gif" data-lazy-src="https://qiniu.codekylin.cn/img/20201026151337.png" alt="image-20201026151336830"></p>
<h3 id="unique-subquery"><a href="#unique-subquery" class="headerlink" title="unique_subquery"></a>unique_subquery</h3><p>该联接类型类似于index_subquery。 子查询中的唯一索引</p>
<p><img src= "https://gitee.com/kylincw/images/raw/master/loading.gif" data-lazy-src="https://qiniu.codekylin.cn/img/20201026151439.png" alt="image-20201026151438195"></p>
<h2 id="possible-keys"><a href="#possible-keys" class="headerlink" title="possible_keys"></a>possible_keys</h2><p>显示可能应用在这张表中的索引，一个或多个。</p>
<p>查询涉及到的字段上若存在索引，则该索引将被列出，<strong>但不一定被查询实际使用</strong></p>
<h2 id="key"><a href="#key" class="headerlink" title="key"></a>key</h2><p><strong>实际使用的索引。如果为NULL，则没有使用索引。</strong></p>
<p><strong>查询中若使用了覆盖索引，则该索引和查询的select字段重叠。</strong></p>
<h2 id="key-len-优化"><a href="#key-len-优化" class="headerlink" title="key_len(优化)"></a>key_len(优化)</h2><p><strong>表示索引中使用的字节数，可通过该列计算查询中使用的索引的长度。</strong></p>
<p><img src= "https://gitee.com/kylincw/images/raw/master/loading.gif" data-lazy-src="https://qiniu.codekylin.cn/img/20201026151749.png" alt="image-20201026151747232"></p>
<p>如何计算</p>
<ol>
<li>先看索引上字段的类型+长度比如 int=4 ;  varchar(20 ) =20 ; char(20 ) =20  </li>
<li>如果是varchar或者char这种字符串字段，视字符集要乘不同的值，比如utf-8 要乘 3,GBK要乘2，</li>
<li>varchar这种动态字符串要加2个字节</li>
<li>允许为空的字段要加1个字节 </li>
</ol>
<p><img src= "https://gitee.com/kylincw/images/raw/master/loading.gif" data-lazy-src="https://qiniu.codekylin.cn/img/20201026151835.png" alt="image-20201026151833574"></p>
<p> 第一组</p>
<p><code>key_len=age的字节长度+name的字节长度=4+1 + ( 20*3+2)=5+62=67</code></p>
<p> 第二组</p>
<p> <code>key_len=age的字节长度=4+1=5</code></p>
<table>
<thead>
<tr>
<th>列类型</th>
<th>keyl_len</th>
<th>备注</th>
</tr>
</thead>
<tbody><tr>
<td>id int</td>
<td>key_len = 4 +1 =5</td>
<td>允许NULL，加1byte</td>
</tr>
<tr>
<td>id int not null</td>
<td>key_len = 4</td>
<td>不允许NULL</td>
</tr>
<tr>
<td>use char(30) utf8</td>
<td>key_len = 30x3+1</td>
<td>允许NULL 字符集utf8</td>
</tr>
<tr>
<td>use varchar(30) not null utf8</td>
<td>key_len = 30x3+2</td>
<td>不允许NULL 字符集utf8 动态列类型，加2byte</td>
</tr>
<tr>
<td>User varchar(30) utf8</td>
<td>key_len = 30x3+2+1</td>
<td>允许NULL 字符集utf8 动态列类型，加2byte</td>
</tr>
<tr>
<td>detail text(10) utf8</td>
<td>key_len = 30x3+2+1</td>
<td>允许NULL Text列截取部分，被视为动态类型，加2byte</td>
</tr>
</tbody></table>
<h2 id="ref-1"><a href="#ref-1" class="headerlink" title="ref"></a>ref</h2><p>显示索引的哪一列被使用了，如果可能的话，是一个常数。哪些列或常量被用于查找索引列上的值.</p>
<p><img src= "https://gitee.com/kylincw/images/raw/master/loading.gif" data-lazy-src="https://qiniu.codekylin.cn/img/20201026152849.png" alt="image-20201026152848245"></p>
<h2 id="rows-优化"><a href="#rows-优化" class="headerlink" title="rows(优化)"></a>rows(优化)</h2><p><strong>rows列显示MySQL认为它执行查询时必须检查的行数。越少越好</strong></p>
<h2 id="filtered"><a href="#filtered" class="headerlink" title="filtered"></a>filtered</h2><p>这个字段表示存储引擎返回的数据在server层过滤后，剩下多少满足查询的记录数量的比例，注意是百分比，不是具体记录数。</p>
<h2 id="Extra-优化"><a href="#Extra-优化" class="headerlink" title="Extra(优化)"></a>Extra(优化)</h2><p><strong>包含不适合在其他列中显示但十分重要的额外信息。</strong></p>
<h3 id="Using-filesort"><a href="#Using-filesort" class="headerlink" title="Using filesort"></a>Using filesort</h3><p><strong>说明mysql会对数据使用一个外部的索引排序，而不是按照表内的索引顺序进行读取。</strong></p>
<p><strong>MySQL中无法利用索引完成的排序操作称为“文件排序”</strong>。<code>order by</code></p>
<p><img src= "https://gitee.com/kylincw/images/raw/master/loading.gif" data-lazy-src="https://qiniu.codekylin.cn/img/20201026153211.png" alt="image-20201026153209573"></p>
<p>优化后，不再出现filesort的情况：</p>
<p><img src= "https://gitee.com/kylincw/images/raw/master/loading.gif" data-lazy-src="https://qiniu.codekylin.cn/img/20201026153315.png" alt="image-20201026153309981"></p>
<p>查询中排序的字段，排序字段若通过索引去访问将大大提高排序速度。</p>
<h3 id="Using-temporary"><a href="#Using-temporary" class="headerlink" title="Using temporary"></a>Using temporary</h3><p><strong>使了用临时表保存中间结果,MySQL在对查询结果排序时使用临时表。常见于排序 <code>order by</code>和分组查询<code>group by</code></strong></p>
<p>优化前存在 using temporary 和 using filesort  </p>
<p><img src= "https://gitee.com/kylincw/images/raw/master/loading.gif" data-lazy-src="https://qiniu.codekylin.cn/img/20201026153524.png" alt="image-20201026153517565"></p>
<p>性能发生明显变化：</p>
<p><img src= "https://gitee.com/kylincw/images/raw/master/loading.gif" data-lazy-src="https://qiniu.codekylin.cn/img/20201026153635.png" alt="image-20201026153632243"></p>
<h3 id="Using-index"><a href="#Using-index" class="headerlink" title="Using index"></a>Using index</h3><p>表示相应的select操作中使用了覆盖索引(Covering Index)，避免访问了表的数据行，效率不错！</p>
<p>如果同时出现using where，表明索引被用来执行索引键值的查找;</p>
<p>如果没有同时出现using where，表明索引只是用来读取数据而非利用索引执行查找。</p>
<h3 id="Using-where"><a href="#Using-where" class="headerlink" title="Using where"></a>Using where</h3><p>表明使用了<code>where</code>过滤，where条件使用了索引</p>
<h3 id="Using-join-buffer"><a href="#Using-join-buffer" class="headerlink" title="Using join buffer"></a>Using join buffer</h3><p>使用了连接缓存</p>
<p><img src= "https://gitee.com/kylincw/images/raw/master/loading.gif" data-lazy-src="https://qiniu.codekylin.cn/img/20201026153832.png" alt="image-20201026153830930"></p>
<h3 id="Impossible-where"><a href="#Impossible-where" class="headerlink" title="Impossible where"></a>Impossible where</h3><p>where子句的值总是false，不能用来获取任何元组,sql写错了</p>
<p><img src= "https://gitee.com/kylincw/images/raw/master/loading.gif" data-lazy-src="https://qiniu.codekylin.cn/img/20201026153956.png" alt="image-20201026153941327"></p>
<h3 id="Select-tables-optimized-away"><a href="#Select-tables-optimized-away" class="headerlink" title="Select tables optimized away"></a>Select tables optimized away</h3><p>在没有GROUPBY子句的情况下，基于索引优化MIN/MAX操作或者</p>
<p>对于MyISAM存储引擎优化COUNT(*)操作，不必等到执行阶段再进行计算，</p>
<p>查询执行计划生成的阶段即完成优化。</p>
<p>在innodb中：</p>
<p><img src= "https://gitee.com/kylincw/images/raw/master/loading.gif" data-lazy-src="https://qiniu.codekylin.cn/img/20201026154150.png" alt="image-20201026154148815"></p>
<p>在Myisam中：</p>
<p><img src= "https://gitee.com/kylincw/images/raw/master/loading.gif" data-lazy-src="https://qiniu.codekylin.cn/img/20201026154244.png" alt="image-20201026154243198"></p>
</article><div class="post-copyright"><div class="post-copyright__author"><span class="post-copyright-meta">文章作者: </span><span class="post-copyright-info"><a href="mailto:undefined">Kylin</a></span></div><div class="post-copyright__type"><span class="post-copyright-meta">文章链接: </span><span class="post-copyright-info"><a href="https://www.codekylin.cn/15002.html">https://www.codekylin.cn/15002.html</a></span></div><div class="post-copyright__notice"><span class="post-copyright-meta">版权声明: </span><span class="post-copyright-info">本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" target="_blank">CC BY-NC-SA 4.0</a> 许可协议。转载请注明来自 <a href="https://www.codekylin.cn" target="_blank">Kylin</a>！</span></div></div><div class="tag_share"><div class="post-meta__tag-list"><a class="post-meta__tags" href="/tags/%E6%95%B0%E6%8D%AE%E5%BA%93/">数据库</a><a class="post-meta__tags" href="/tags/MySQL/">MySQL</a></div><div class="post_share"><div class="social-share" data-image="https://qiniu.codekylin.cn/github/img/img/deepin-1.png" data-sites="facebook,twitter,wechat,weibo,qq"></div><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/social-share.js/dist/css/share.min.css" media="print" onload="this.media='all'"><script src="https://cdn.jsdelivr.net/npm/social-share.js/dist/js/social-share.min.js" defer></script></div></div><div class="post-reward"><div class="reward-button button--animated"><i class="fas fa-qrcode"></i> 打赏</div><div class="reward-main"><ul class="reward-all"><li class="reward-item"><a href="https://qiniu.codekylin.cn/img/20200807181442.jpg" target="_blank"><img class="post-qr-code-img" data-lazy-src="https://qiniu.codekylin.cn/img/20200807181442.jpg" alt="微信"/></a><div class="post-qr-code-desc">微信</div></li><li class="reward-item"><a href="https://qiniu.codekylin.cn/img/20200807181505.jpg" target="_blank"><img class="post-qr-code-img" data-lazy-src="https://qiniu.codekylin.cn/img/20200807181505.jpg" alt="支付寶"/></a><div class="post-qr-code-desc">支付寶</div></li></ul></div></div><nav class="pagination-post" id="pagination"><div class="prev-post pull-left"><a href="/24797.html"><img class="prev-cover" data-lazy-src="https://qiniu.codekylin.cn/github/img/img/code1.jpg" onerror="onerror=null;src='/img/404.jpg'" alt="cover of previous post"><div class="pagination-info"><div class="label">上一篇</div><div class="prev_info">MySQL索引优化</div></div></a></div><div class="next-post pull-right"><a href="/33592.html"><img class="next-cover" data-lazy-src="https://qiniu.codekylin.cn/github/img/img/荒鲸.png" onerror="onerror=null;src='/img/404.jpg'" alt="cover of next post"><div class="pagination-info"><div class="label">下一篇</div><div class="next_info">MySQL索引</div></div></a></div></nav><div class="relatedPosts"><div class="headline"><i class="fas fa-thumbs-up fa-fw"></i><span> 相关推荐</span></div><div class="relatedPosts-list"><div><a href="/16118.html" title="MySQL主从复制"><img class="cover" data-lazy-src="https://qiniu.codekylin.cn/github/img/img/wallhaven-3kp6yv.jpg" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2020-10-29</div><div class="title">MySQL主从复制</div></div></a></div><div><a href="/14571.html" title="MySQL存储引擎"><img class="cover" data-lazy-src="https://qiniu.codekylin.cn/github/img/img/博客封面18.png" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2020-10-25</div><div class="title">MySQL存储引擎</div></div></a></div><div><a href="/40460.html" title="MySQL之查询截取分析"><img class="cover" data-lazy-src="https://qiniu.codekylin.cn/github/img/img/deepin-2.png" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2020-10-27</div><div class="title">MySQL之查询截取分析</div></div></a></div><div><a href="/34856.html" title="MySQL数据库-1"><img class="cover" data-lazy-src="https://qiniu.codekylin.cn/github/images/20200718200005.jpg" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2019-09-28</div><div class="title">MySQL数据库-1</div></div></a></div><div><a href="/33592.html" title="MySQL索引"><img class="cover" data-lazy-src="https://qiniu.codekylin.cn/github/img/img/荒鲸.png" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2020-10-25</div><div class="title">MySQL索引</div></div></a></div><div><a href="/35176.html" title="MySQL数据库-2"><img class="cover" data-lazy-src="https://qiniu.codekylin.cn/img/20200708172722.jpg" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2019-09-28</div><div class="title">MySQL数据库-2</div></div></a></div></div></div><hr/><div id="post-comment"><div class="comment-head"><div class="comment-headline"><i class="fas fa-comments fa-fw"></i><span> 评论</span></div></div><div class="comment-wrap"><div><div class="vcomment" id="vcomment"></div></div></div></div></div><div class="aside-content" id="aside-content"><div class="card-widget card-info"><div class="card-info-avatar is-center"><img class="avatar-img" data-lazy-src="https://qiniu.codekylin.cn/img/20200807181526.jpg" onerror="this.onerror=null;this.src='https://qiniu.codekylin.cn/github/img/friend_404.gif'" alt="avatar"/><div class="author-info__name">Kylin</div><div class="author-info__description">学习不易，努力努力~</div></div><div class="card-info-data"><div class="card-info-data-item is-center"><a href="/archives/"><div class="headline">文章</div><div class="length-num">362</div></a></div><div class="card-info-data-item is-center"><a href="/tags/"><div class="headline">标签</div><div class="length-num">427</div></a></div><div class="card-info-data-item is-center"><a href="/categories/"><div class="headline">分类</div><div class="length-num">101</div></a></div></div><a class="button--animated" id="card-info-btn"><i class="fas fa-bookmark"></i><span>加入书签</span></a><div class="card-info-social-icons is-center"><a class="social-icon" href="https://github.com/kylincw" target="_blank" title="Github"><i class="iconfont icon-github"></i></a><a class="social-icon" href="tencent://message/?Menu=yes&amp;uin=171346168&amp;Service=300&amp;sigT=45a1e5847943b64c6ff3990f8a9e644d2b31356cb0b4ac6b24663a3c8dd0f8aa12a595b1714f9d45" target="_blank" title="qq"><i class="iconfont icon-qq"></i></a><a class="social-icon" href="https://space.bilibili.com/53836035" target="_blank" title="BiliBili"><i class="iconfont icon-bilibili-line"></i></a><a class="social-icon" href="mailto:zhang171346168@qq.com" target="_blank" title="Email"><i class="iconfont icon-email1"></i></a><a class="social-icon" href="/atom.xml" target="_blank" title="RSS"><i class="iconfont icon-rss"></i></a></div></div><div class="card-widget card-announcement"><div class="item-headline"><i class="fas fa-bullhorn card-announcement-animation"></i><span>公告</span></div><div class="announcement_content">学习不易，努力努力！</div></div><div class="sticky_layout"><div class="card-widget" id="card-toc"><div class="item-headline"><i class="fas fa-stream"></i><span>目录</span></div><div class="toc-content"><ol class="toc"><li class="toc-item toc-level-2"><a class="toc-link" href="#%E7%AE%80%E4%BB%8B"><span class="toc-number">1.</span> <span class="toc-text">简介</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#id-%E9%87%8D%E8%A6%81"><span class="toc-number">2.</span> <span class="toc-text">id(重要)</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#select-type"><span class="toc-number">3.</span> <span class="toc-text">select_type</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#SIMPLE"><span class="toc-number">3.1.</span> <span class="toc-text">SIMPLE</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#PRIMARY"><span class="toc-number">3.2.</span> <span class="toc-text">PRIMARY</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#DERIVED"><span class="toc-number">3.3.</span> <span class="toc-text">DERIVED</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#SUBQUERY"><span class="toc-number">3.4.</span> <span class="toc-text">SUBQUERY</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#DEPENDENT-SUBQUERY"><span class="toc-number">3.5.</span> <span class="toc-text">DEPENDENT SUBQUERY</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#UNCACHEABLE-SUBQUREY"><span class="toc-number">3.6.</span> <span class="toc-text">UNCACHEABLE SUBQUREY</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#UNION"><span class="toc-number">3.7.</span> <span class="toc-text">UNION</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#UNION-RESULT"><span class="toc-number">3.8.</span> <span class="toc-text">UNION RESULT</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#table"><span class="toc-number">4.</span> <span class="toc-text">table</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#partitions"><span class="toc-number">5.</span> <span class="toc-text">partitions</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#type-%E4%BC%98%E5%8C%96"><span class="toc-number">6.</span> <span class="toc-text">type(优化)</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#system"><span class="toc-number">6.1.</span> <span class="toc-text">system</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#const"><span class="toc-number">6.2.</span> <span class="toc-text">const</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#eq-ref"><span class="toc-number">6.3.</span> <span class="toc-text">eq_ref</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#ref"><span class="toc-number">6.4.</span> <span class="toc-text">ref</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#range"><span class="toc-number">6.5.</span> <span class="toc-text">range</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#index"><span class="toc-number">6.6.</span> <span class="toc-text">index</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#all"><span class="toc-number">6.7.</span> <span class="toc-text">all</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#index-merge"><span class="toc-number">6.8.</span> <span class="toc-text">index_merge</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#ref-or-null"><span class="toc-number">6.9.</span> <span class="toc-text">ref_or_null</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#index-subquery"><span class="toc-number">6.10.</span> <span class="toc-text">index_subquery</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#unique-subquery"><span class="toc-number">6.11.</span> <span class="toc-text">unique_subquery</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#possible-keys"><span class="toc-number">7.</span> <span class="toc-text">possible_keys</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#key"><span class="toc-number">8.</span> <span class="toc-text">key</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#key-len-%E4%BC%98%E5%8C%96"><span class="toc-number">9.</span> <span class="toc-text">key_len(优化)</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#ref-1"><span class="toc-number">10.</span> <span class="toc-text">ref</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#rows-%E4%BC%98%E5%8C%96"><span class="toc-number">11.</span> <span class="toc-text">rows(优化)</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#filtered"><span class="toc-number">12.</span> <span class="toc-text">filtered</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#Extra-%E4%BC%98%E5%8C%96"><span class="toc-number">13.</span> <span class="toc-text">Extra(优化)</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#Using-filesort"><span class="toc-number">13.1.</span> <span class="toc-text">Using filesort</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#Using-temporary"><span class="toc-number">13.2.</span> <span class="toc-text">Using temporary</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#Using-index"><span class="toc-number">13.3.</span> <span class="toc-text">Using index</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#Using-where"><span class="toc-number">13.4.</span> <span class="toc-text">Using where</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#Using-join-buffer"><span class="toc-number">13.5.</span> <span class="toc-text">Using join buffer</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#Impossible-where"><span class="toc-number">13.6.</span> <span class="toc-text">Impossible where</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#Select-tables-optimized-away"><span class="toc-number">13.7.</span> <span class="toc-text">Select tables optimized away</span></a></li></ol></li></ol></div></div><div class="card-widget card-recent-post"><div class="item-headline"><i class="fas fa-history"></i><span>最新文章</span></div><div class="aside-list"><div class="aside-list-item"><a class="thumbnail" href="/56352.html" title="be动词"><img data-lazy-src="https://qiniu.codekylin.cn/github/img/img/博客封面10.png" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="be动词"/></a><div class="content"><a class="title" href="/56352.html" title="be动词">be动词</a><time datetime="2022-07-12T11:47:29.800Z" title="更新于 2022-07-12 19:47:29">2022-07-12</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/36436.html" title="JVM堆内存"><img data-lazy-src="https://qiniu.codekylin.cn/img/20200418115059.jpg" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="JVM堆内存"/></a><div class="content"><a class="title" href="/36436.html" title="JVM堆内存">JVM堆内存</a><time datetime="2022-07-12T11:47:29.800Z" title="更新于 2022-07-12 19:47:29">2022-07-12</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/44292.html" title="Java多线程详解"><img data-lazy-src="https://qiniu.codekylin.cn/github/img/img/wallhaven-eorjzk.png" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="Java多线程详解"/></a><div class="content"><a class="title" href="/44292.html" title="Java多线程详解">Java多线程详解</a><time datetime="2022-07-12T11:47:29.800Z" title="更新于 2022-07-12 19:47:29">2022-07-12</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/40200.html" title="谷粒商城记录"><img data-lazy-src="https://qiniu.codekylin.cn/github/img/img/wallhaven-6qvvrx.jpg" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="谷粒商城记录"/></a><div class="content"><a class="title" href="/40200.html" title="谷粒商城记录">谷粒商城记录</a><time datetime="2022-07-12T11:47:29.800Z" title="更新于 2022-07-12 19:47:29">2022-07-12</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/27082.html" title="Spring学习-3"><img data-lazy-src="https://qiniu.codekylin.cn/github/img/img/wallhaven-4x28xo.jpg" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="Spring学习-3"/></a><div class="content"><a class="title" href="/27082.html" title="Spring学习-3">Spring学习-3</a><time datetime="2022-07-12T11:47:29.799Z" title="更新于 2022-07-12 19:47:29">2022-07-12</time></div></div></div></div></div></div></main><footer id="footer" style="background-image: url('https://qiniu.codekylin.cn/github/img/img/deepin-1.png')"><div id="footer-wrap"><div class="copyright">&copy;2019 - 2022 By Kylin</div><div class="framework-info"><span>框架 </span><a target="_blank" rel="noopener" href="https://hexo.io">Hexo</a><span class="footer-separator">|</span><span>主题 </span><a target="_blank" rel="noopener" href="https://github.com/jerryc127/hexo-theme-butterfly">Butterfly</a></div><div class="footer_custom_text"><a target="_blank" rel="noopener" href="https://beian.miit.gov.cn/"><img class="icp-icon" src="https://img.alicdn.com/tfs/TB1..50QpXXXXX7XpXXXXXXXXXX-40-40.png"><span>湘ICP备2022005420号-1</span></a></div></div></footer></div><div id="rightside"><div id="rightside-config-hide"><button id="readmode" type="button" title="阅读模式"><i class="fas fa-book-open"></i></button><button id="font-plus" type="button" title="放大字体"><i class="fas fa-plus"></i></button><button id="font-minus" type="button" title="缩小字体"><i class="fas fa-minus"></i></button><button id="translateLink" type="button" title="简繁转换">繁</button><button id="darkmode" type="button" title="浅色和深色模式转换"><i class="fas fa-adjust"></i></button><button id="hide-aside-btn" type="button" title="单栏和双栏切换"><i class="fas fa-arrows-alt-h"></i></button></div><div id="rightside-config-show"><button id="rightside_config" type="button" title="设置"><i class="fas fa-cog fa-spin"></i></button><button class="close" id="mobile-toc-button" type="button" title="目录"><i class="fas fa-list-ul"></i></button><a id="to_comment" href="#post-comment" title="直达评论"><i class="fas fa-comments"></i></a><button id="go-up" type="button" title="回到顶部"><i class="fas fa-arrow-up"></i></button></div></div><div id="local-search"><div class="search-dialog"><div class="search-dialog__title" id="local-search-title">本地搜索</div><div id="local-input-panel"><div id="local-search-input"><div class="local-search-box"><input class="local-search-box--input" placeholder="搜索文章" type="text"/></div></div></div><hr/><div id="local-search-results"></div><span class="search-close-button"><i class="fas fa-times"></i></span></div><div id="search-mask"></div></div><div><script src="/js/utils.js"></script><script src="/js/main.js"></script><script src="/js/tw_cn.js"></script><script src="https://cdn.jsdelivr.net/npm/instant.page/instantpage.min.js" type="module"></script><script src="https://cdn.jsdelivr.net/npm/vanilla-lazyload/dist/lazyload.iife.min.js"></script><script src="https://cdn.jsdelivr.net/npm/node-snackbar/dist/snackbar.min.js"></script><script src="/js/search/local-search.js"></script><div class="js-pjax"><script>function loadValine () {
  function initValine () {
    const valine = new Valine(Object.assign({
      el: '#vcomment',
      appId: 'ClIyIUhj1ue2rcRTsApYCR50-gzGzoHsz',
      appKey: 'ATug9IScYQBHILhKWEqBHYxM',
      placeholder: '昵称填入QQ号能获取到QQ头像哦~请输入正确的邮箱地址，你将会快速收到我的回复并且通过邮件通知你！~',
      avatar: 'robohash',
      meta: 'nick,mail,link'.split(','),
      pageSize: '10',
      lang: 'zh-cn',
      recordIP: false,
      serverURLs: 'https://cliyiuhj.lc-cn-n1-shared.com',
      emojiCDN: '',
      emojiMaps: "",
      enableQQ: true,
      path: window.location.pathname,
      requiredFields: ["nick,mail"],
      visitor: false
    }, null))
  }

  if (typeof Valine === 'function') initValine() 
  else getScript('https://cdn.jsdelivr.net/npm/valine/dist/Valine.min.js').then(initValine)
}

if ('Valine' === 'Valine' || !true) {
  if (true) btf.loadComment(document.getElementById('vcomment'),loadValine)
  else setTimeout(loadValine, 0)
} else {
  function loadOtherComment () {
    loadValine()
  }
}</script></div><script defer="defer" id="ribbon" src="https://cdn.jsdelivr.net/npm/butterfly-extsrc@1/dist/canvas-ribbon.min.js" size="150" alpha="0.6" zIndex="-1" mobile="false" data-click="true"></script><script defer="defer" id="fluttering_ribbon" mobile="false" src="https://cdn.jsdelivr.net/npm/butterfly-extsrc@1/dist/canvas-fluttering-ribbon.min.js"></script></div></body></html>